package org.hhchat.leetcode.tree;

import org.hhchat.leetcode.dataStruct.TreeNode;

/**
 * Created this one by HMH on 2017/10/1.
 */
public class code671_easy {
    public static void main(String[] args){

    }

    class Solution {
        int min2 = Integer.MAX_VALUE;
        int min = Integer.MAX_VALUE;

        public int findSecondMinimumValue(TreeNode root) {
            visitAll(root);
            return min2 == Integer.MAX_VALUE ? -1 : min2;
        }

        public void visitAll(TreeNode root) {
            if (root == null) {
                return;
            }
            visit(root.val);
            if (root.left != null) {
                visitAll(root.left);
            }
            if (root.right != null) {
                visitAll(root.right);
            }
        }

        public void visit(int n) {
            if (n <= min) {
                min = n;
            } else if (n < min2) {
                min2 = n;
            }
        }
    }


}
